<?php
/**
 * Created by JetBrains PhpStorm.
 * User: shaoshuai
 * Date: 11-10-3
 * Time: PM4:03
 */

include_once '../common.func.php';

$navs = getNavs();

$id = intval($_POST['id']);
$text = trim($_POST['text']);
$href = trim($_POST['href']);
$target = (trim($_POST['target']) == '_blank' ? '_blank' : '_self');

if ($_POST['action'] == '保存') {
    if ($navs[$id]) {
        $navs[$id] = array('text' => $text, 'href' => $href, 'target' => $target);
        saveNavs($navs);
    }
} elseif ($_POST['action'] == '删除') {
    unset($navs[$id]);
    saveNavs(array_values($navs));
} elseif ($_POST['action'] == '添加') {
    array_push($navs, array('text' => $text, 'href' => $href, 'target' => $target));
    saveNavs($navs);
}


header('Location: ' . SITE_URL . '/admin/nav.php');
